//
//  OrgNameCell.m
//  TourPlay
//
//  Created by dllo on 15/11/24.
//  Copyright © 2015年 王军岐. All rights reserved.
//

#import "OrgNameCell.h"
#define WIDTH 8
#define HEIGHT 6

@interface OrgNameCell ()

@property (nonatomic, retain) UIView *viewBack;
@property (nonatomic, retain) UIImageView *orgImageV;
@property (nonatomic, retain) UILabel *orgName;
@property (nonatomic, retain) UIImageView *rightImageV;

@end



@implementation OrgNameCell
- (void)dealloc
{
    [_viewBack release];
    [_orgImageV release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews
{
    self.viewBack = [[UIView alloc] initWithFrame:CGRectMake(WIDTH, 0, SCREEN_WIDTH - WIDTH * 2, 50 + 50 + 10 + 40 + 10)];
    //    self.viewBack.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.9f];
    self.viewBack.backgroundColor = [UIColor whiteColor];
        self.viewBack.layer.cornerRadius = 4.f;
    [self.contentView addSubview:self.viewBack];
    [_viewBack release];
    UILabel *titleL = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.viewBack.frame.size.width, 40)];
//    titleL.backgroundColor = [UIColor orangeColor];
    titleL.text = @"发起人";
    titleL.textAlignment = NSTextAlignmentCenter;
    titleL.font = [UIFont systemFontOfSize:16.f];
    titleL.textColor = [UIColor colorWithRed:0.71 green:0.68 blue:0.69 alpha:1];
    [self.viewBack addSubview:titleL];
    [titleL release];
    
    self.orgImageV = [[UIImageView alloc] initWithFrame:CGRectMake((self.viewBack.frame.size.width - 50) / 2.f, titleL.frame.size.height + 10, 50, 50)];
    // 裁掉边框
    self.orgImageV.layer.masksToBounds = YES;
    self.orgImageV.layer.cornerRadius = self.orgImageV.frame.size.width / 2.f;
    self.orgImageV.contentMode = UIViewContentModeScaleAspectFill;
    [self.viewBack addSubview:self.orgImageV];
    [_orgImageV release];
    
    self.orgName = [[UILabel alloc] initWithFrame:CGRectMake(titleL.frame.origin.x, self.orgImageV.frame.origin.y + self.orgImageV.frame.size.height + 10, titleL.frame.size.width, titleL.frame.size.height)];
    self.orgName.textAlignment = NSTextAlignmentCenter;
    self.orgName.font = [UIFont systemFontOfSize:16.f];
    self.orgName.textColor = [UIColor colorWithRed:0.39 green:0.34 blue:0.35 alpha:1];
    [self.viewBack addSubview:self.orgName];
    [_orgName release];

    
    // 夜间模式
    [self addColorChangedBlock:^{
        
        self.viewBack.nightBackgroundColor = [ColorSingleton shareSingleton].cellColor;
        self.viewBack.normalBackgroundColor = [ColorSingleton shareSingleton].cellColor;
        
    }];
}
- (UIImageView *)rightImageV
{
    if (nil == _rightImageV) {
        self.rightImageV = [[UIImageView alloc] initWithFrame:CGRectMake(self.viewBack.frame.size.width - 12 - 10, self.viewBack.frame.size.height / 2.f - 6, 6, 12)];
        self.rightImageV.image = [UIImage imageNamed:@"find_calendar_switching_right_notclickable@3x.png"];
        //    imageV.backgroundColor = [UIColor orangeColor];
         [self.viewBack addSubview:self.rightImageV];
        [_rightImageV release];
       
    }
    return _rightImageV;
}
- (void)setActivityMod:(ActivityModel *)activityMod
{
    if (_activityMod != activityMod) {
        [_activityMod release];
        _activityMod = [activityMod retain];
    }
    NSURL *urlOrg = [NSURL URLWithString:self.activityMod.orgavatar];
    [self.orgImageV sd_setImageWithURL:urlOrg placeholderImage:[UIImage imageNamed:@"detail_touxiang@2x.png"]];
    
    self.orgName.text = self.activityMod.orgname;
    

    
    if ([activityMod.orgname isEqualToString:@"大麦网"] || 0 == activityMod.orgname.length) {
        self.orgImageV.image = [UIImage imageNamed:@"play_damai.jpg"];
        self.orgName.text = @"大麦网";
    } else {
        self.rightImageV.backgroundColor = [UIColor clearColor];
    }
//     NSLog(@"orgname: %@", self.activityMod.orgname);
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
